Skip to content

Fix Notifier async callback error handling - #2096

Open
timothyanderson096-ocdealcheck wants to merge 5 commits into
hardbyte:mainfrom
timothyanderson096-ocdealcheck:fix-notifier-async-errors-1912
Open

Fix Notifier async callback error handling#2096
timothyanderson096-ocdealcheck wants to merge 5 commits into
hardbyte:mainfrom
timothyanderson096-ocdealcheck:fix-notifier-async-errors-1912

Conversation

@timothyanderson096-ocdealcheck

Copy link
Copy Markdown

Summary

Route listener exceptions through Notifier._on_error() when a Notifier is using an asyncio event loop.

With a loop configured, thread-backed receivers currently schedule _on_message_received() using call_soon_threadsafe(). Exceptions raised by synchronous listeners therefore occur later on the event-loop thread and bypass _rx_thread()'s exception handler. Coroutine listeners have the same problem because their tasks are only discarded on completion, so task exceptions are never passed to _on_error().

This change:

  • wraps event-loop message dispatch so synchronous listener exceptions populate Notifier.exception and call _on_error()
  • applies the same guarded dispatch to file-descriptor based loop readers
  • inspects completed coroutine tasks, routes their exceptions through _on_error(), and keeps cancelled tasks quiet
  • adds regression tests for both synchronous and asynchronous listener failures while an asyncio loop is configured

The existing no-loop receive-thread behavior is unchanged.

Fixes #1912.

@mergify

mergify Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors in callbacks when running async is not calling _on_error()

1 participant